//
//  FirstPhotoViewController.m
//  旅游咨询
//
//  Created by 高建 on 15/4/16.
//  Copyright (c) 2015年 xubin. All rights reserved.
//

#import "FirstPhotoViewController.h"

@interface FirstPhotoViewController ()

@end

@implementation FirstPhotoViewController

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor greenColor];
    
//    [self.navigationController setNavigationBarHidden:NO];
     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:(UIBarButtonItemStylePlain) target:self action:@selector(popViewRootViewController)];
    UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc] init];
    flowLayOut.itemSize = CGSizeMake(WidthZ * 0.293, HeighZ * 0.165);
    flowLayOut.sectionInset = UIEdgeInsetsMake(WidthZ * 0.04, HeighZ * 0.0225, WidthZ * 0.02667, HeighZ * 0.0225);
    flowLayOut.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayOut.minimumInteritemSpacing = 3;
    
    //集合视图
    UICollectionView *myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WidthZ, HeighZ - 64) collectionViewLayout:flowLayOut];
    [self.view addSubview:myCollectionView];
    myCollectionView.backgroundColor = [UIColor whiteColor];
    myCollectionView.delegate = self;
    myCollectionView.dataSource = self;
    [myCollectionView release];
    
    //注册cell
    [myCollectionView registerClass:[FirstPhotoCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    NSLog(@" %@", self.MyFirstPhoto);
    [MyAFNData getNetData:self.MyFirstPhoto responseGETData:^(id data) {
        self.firstPhotoArray = [NSMutableArray array];
        
        NSMutableArray *array = [data objectForKey:@"items"];
        
        for (NSMutableDictionary *InLandDic in array) {
            photoModel *myPhotoModel = [[photoModel alloc] init];
            [myPhotoModel setValuesForKeysWithDictionary:InLandDic];
            [self.firstPhotoArray addObject:myPhotoModel];
            [myPhotoModel release];
            
            //          NSLog(@"++++++++++++++++%@",self.inLandCityArray);
            
        }
        [myCollectionView reloadData];
        
    }];

    
    
}

- (void)popViewRootViewController
{
    [self.navigationController popViewControllerAnimated:YES];
   
}

//显示item上的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    FirstPhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    
    //改变边框形状
    cell.PhotoImageView.layer.masksToBounds = YES;
    cell.PhotoImageView.layer.cornerRadius = 3;
    
    photoModel *myPhotoModel = [self.firstPhotoArray objectAtIndex:indexPath.row];
//    NSLog(@"++++++++++++++++_+++++++++%@",myPhotoModel);
    
    cell.firstPhoto = myPhotoModel;
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    FirstCrameViewController *firstCrame = [[FirstCrameViewController alloc]init];
    firstCrame.FirstCramePhotoArray = self.firstPhotoArray;
//    [firstCrame.navigationController setNavigationBarHidden:YES];
    firstCrame.index = indexPath.row;
    [self.navigationController pushViewController:firstCrame animated:YES];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.firstPhotoArray.count;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
